<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function Person(name, age) {
            this.name = name;
            this.age = age;
            this.sayHi = sayHi;
        }
        function sayHi() {
            console.log('你好');
        }
        sayHi = 10;
        var sy = new Person('孙悦',30);
        var yq = new Person('于谦',40);
        console.log(sy.sayHi == yq.sayHi);
        sy.sayHi();
        // 构造函数创建多个对象时，有相同需要用的方法时，浪费空间
        // 解决办法：使用原型来解决，共享属性和方法，节省空间
    </script>
</body>
</html>